Skip to main content

MQTT Communication Setup

This guide shows you how to configure MQTT communication between your OV20i camera and external devices using Node-RED. MQTT enables lightweight, reliable messaging for IoT applications and remote device communication.

When to Use MQTT Communication: IoT device integration, remote monitoring systems, publish/subscribe messaging patterns, low-bandwidth environments, distributed sensor networks, or when you need reliable message delivery with automatic reconnection.

Prerequisites

  • OV20i camera system set up and connected
  • Network connectivity between camera and MQTT broker
  • MQTT broker available (local or cloud-based)
  • Basic understanding of MQTT concepts (topics, publish/subscribe)
  • Active recipe configured on the camera

MQTT Communication Overview

MQTT Key Concepts:

  • Broker: Central server that routes messages between clients
  • Topics: Message categories (e.g., "camera/status", "commands/trigger")
  • Publish: Send messages to a topic
  • Subscribe: Receive messages from a topic
  • QoS: Quality of Service levels (0, 1, 2)

Step 1: Verify Network Configuration

1.1 Check Camera Network Settings

  1. Navigate to System Settings
  2. Note camera IP address (e.g., 192.168.0.100)
  3. Verify network connectivity to MQTT broker

1.2 MQTT Broker Requirements

Ensure MQTT broker accessibility:

  • Same network: Camera must reach broker IP address
  • Port access: Default MQTT port 1883 (or 8883 for TLS)
  • Authentication: Username/password if broker requires it
  • Firewall: Allow MQTT traffic on required ports

1.3 Network Requirements

ComponentIP AddressPortNotes
Camera192.168.0.100N/AMust reach broker
MQTT Broker192.168.0.2001883Standard MQTT port
Client Devices192.168.0.xxxVariableAny devices subscribing

Step 2: Access Node-RED Editor

2.1 Navigate to IO Block

  1. Open your active recipe in Recipe Editor
  2. Click "IO Block" in breadcrumb menu
  3. Click "Configure IO" to enter Node-RED editor

2.2 Verify MQTT Nodes Available

Check Node-RED palette for MQTT nodes:

  • mqtt in - Subscribe to MQTT topics
  • mqtt out - Publish to MQTT topics

Checkpoint: You should see MQTT nodes in the Network section of the left panel.

Step 3: Configure MQTT Broker Connection

3.1 Add MQTT Broker Configuration

  1. Drag "mqtt in" node onto canvas (for initial setup)
  2. Double-click the node to open configuration
  3. Click pencil icon next to Server field
  4. Click "Add new mqtt-broker"

3.2 Configure Broker Settings

Basic Broker Configuration:

SettingValueDescription
NameCamera MQTT BrokerDescriptive identifier
Server192.168.0.200MQTT broker IP address
Port1883Standard MQTT port
ProtocolMQTT V3.1.1Recommended version
Client ID(auto-generate)Leave blank for automatic

3.3 Authentication Settings (If Required)

If broker requires authentication:

SettingDescription
UsernameMQTT broker username
PasswordMQTT broker password
Use TLSEnable for secure connections (port 8883)

3.4 Advanced Settings

Connection Options:

SettingRecommended ValueDescription
Keep Alive60 secondsHeartbeat interval
Clean SessionTrueStart fresh each connection
Auto ConnectTrueReconnect automatically

3.5 Save Broker Configuration

  1. Click "Add" to save broker settings
  2. Click "Done" to close node configuration
  3. Broker configuration is now available for all MQTT nodes

Step 4: Configure MQTT Input (Subscribe)

4.1 Set Up MQTT In Node

  1. Select the "mqtt in" node you added
  2. Double-click to configure
  3. Configure subscription settings:

4.2 MQTT In Configuration

Subscription Settings:

SettingExample ValueDescription
ServerCamera MQTT BrokerSelect configured broker
Topiccamera/commandsTopic to subscribe to
QoS0Message delivery quality
Outputauto-detectMessage format
NameCommand ListenerNode identifier

4.3 Topic Naming Conventions

Recommended topic structure:

PurposeTopic ExampleUsage
Commandscamera/commandsReceive control commands
Status requestscamera/status/requestStatus information requests
Configurationcamera/configConfiguration changes

4.4 Configure Message Processing

  1. Add "debug" node to monitor incoming messages
  2. Connect: MQTT In → Debug
  3. Configure debug node to show complete message

Step 5: Configure MQTT Output (Publish)

5.1 Add MQTT Out Node

  1. Drag "mqtt out" node onto canvas
  2. Double-click to configure
  3. Select same broker configuration

5.2 MQTT Out Configuration

Publishing Settings:

SettingExample ValueDescription
ServerCamera MQTT BrokerSame broker as input
Topiccamera/responsesTopic for camera responses
QoS0Message delivery quality
RetainFalseDon't store last message
NameResponse PublisherNode identifier

5.3 Response Topic Structure

Recommended response topics:

Response TypeTopic ExampleUsage
Status updatescamera/statusCamera status information
Resultscamera/resultsInspection results
Acknowledgmentscamera/ackCommand confirmations

Step 6: Create Basic Communication Flow

6.1 Build Outgoing Message Flow

Create a flow to publish messages from the camera:

  1. Add "inject" node for triggering messages
  2. Add "function" node for message formatting
  3. Add "mqtt out" node for publishing
  4. Connect: Inject → Function → MQTT Out

6.2 Build Incoming Message Flow

Create a separate flow to receive messages:

  1. Add "mqtt in" node for subscribing
  2. Add "debug" node for monitoring
  3. Connect: MQTT In → Debug

6.3 Configure Inject Node

  1. Double-click inject node
  2. Configure settings:
    • Name: "Send Test Message"
    • Payload: Timestamp
    • Topic: (leave empty)
  3. Click "Done"

6.4 Configure Function Node

Simple message formatting:

// Format outgoing message
msg.topic = "camera/status";
msg.payload = "Camera online - " + new Date().toISOString();
return msg;

  1. Double-click function node
  2. Copy code above into "On Message" tab
  3. Name: "Format Message"
  4. Click "Done"

6.5 Configure MQTT Out Node

  1. Double-click mqtt out node
  2. Select broker: Camera MQTT Broker (configured earlier)
  3. Topic: (leave empty - set by function node)
  4. Name: "Publish Status"
  5. Click "Done"

6.6 Configure MQTT In Node

  1. Double-click mqtt in node
  2. Select broker: Camera MQTT Broker
  3. Topic: camera/commands
  4. Name: "Command Listener"
  5. Click "Done"

6.7 Configure Debug Node

  1. Double-click debug node
  2. Output: Complete msg object
  3. Name: "Incoming Messages"
  4. Click "Done"

6.8 Final Flow Structure

Your complete flow should be:

Outgoing: Inject → Function → MQTT Out Incoming: MQTT In → Debug

Step 7: Deploy and Test Configuration

7.1 Deploy Flow

  1. Click "Deploy" button (top-right corner)
  2. Verify deployment success message
  3. Check node status indicators:
    • Green dot: Connected to broker
    • Red dot: Connection failed
    • Yellow dot: Connecting

7.2 Test Internal Communication

Test the camera's MQTT publishing:

  1. Click inject button to send test message
  2. Verify MQTT Out node shows activity
  3. Check debug panel if you have external messages

7.3 External Testing (Optional)

Test with external MQTT client to send commands to camera:

Using command line tools:

# Send a test command to the camera
mosquitto_pub -h 192.168.0.100 -t "camera/commands" -m "test_command"

Expected result: Debug node should show the incoming message in Node-RED debug panel.

7.4 Verify Communication

Check these aspects:

TestExpected ResultStatus
Broker connectionGreen status on MQTT nodes
Message publishingInject triggers MQTT Out successfully
Message receptionDebug shows external messages
ReconnectionAuto-reconnect after network interruption

Step 8: Troubleshooting MQTT Issues

8.1 Connection Problems

ProblemSymptomsSolution
Cannot connect to brokerRed status indicatorsCheck broker IP and port
Authentication failureConnection refusedVerify username/password
Network timeoutsYellow connecting statusCheck network connectivity
Firewall blockingNo connection attemptOpen MQTT ports

8.2 Message Issues

ProblemSymptomsSolution
No messages receivedDebug shows nothingCheck topic subscriptions
Messages not publishingExternal clients see nothingVerify publish topics
Message format errorsParsing failuresUse simple text messages
Lost messagesIntermittent deliveryCheck broker connection

8.3 Performance Issues

ProblemSymptomsSolution
High latencyDelayed message deliveryCheck broker performance
Connection dropsFrequent reconnectionsAdjust keep-alive settings
Message floodingBroker overloadImplement message throttling

8.4 Debug Techniques

Systematic troubleshooting:

  1. Check broker connection status in Node-RED
  2. Monitor Node-RED debug panel for message flow
  3. Use simple text messages before complex data
  4. Verify network connectivity with ping
  5. Test with basic topics before advanced flows

Success! Your MQTT Communication is Ready

Your MQTT communication system can now:

  • Connect to MQTT brokers with proper authentication
  • Subscribe to topics for receiving commands and data
  • Publish messages for status updates and responses
  • Handle JSON message formats for structured communication
  • Automatically reconnect after network interruptions
  • Support multiple QoS levels for different message priorities

Ongoing Maintenance

Regular System Checks

  • Monitor broker connection status in Node-RED
  • Verify message delivery with test messages
  • Check broker logs for any error patterns
  • Update authentication credentials as needed

Performance Monitoring

  • Track message latency and delivery times
  • Monitor broker resource usage for scalability
  • Analyze topic usage patterns for optimization
  • Review QoS settings based on actual requirements

Next Steps

After setting up basic MQTT communication:

  1. Implement specific messaging workflows for your application
  2. Set up topic hierarchies for organized communication
  3. Add security measures like TLS encryption
  4. Integrate with external systems using established MQTT protocols
  5. Create monitoring dashboards for system health

🔗 See Also